package com.example.administrator.daggerdemo.presenter;

import com.example.administrator.daggerdemo.MyApplication;
import com.example.administrator.daggerdemo.base2.base.BaseObserver;
import com.example.administrator.daggerdemo.base2.base.BasePresenterImpl;
import com.example.administrator.daggerdemo.model.network.request.GetgrowRequestInfo;
import com.example.administrator.daggerdemo.model.network.response.GetgrowResponseInfo;
import com.example.administrator.daggerdemo.utils.DateUtils;
import com.example.administrator.daggerdemo.utils.PhoneUtils;
import com.example.administrator.daggerdemo.view.IGrowthActivityView;

import org.json.JSONException;

import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by zhengjian on 2016/12/13.
 */
public class GrowthActivityPresenter extends BasePresenterImpl<IGrowthActivityView> {
    /**
     * 构造方法
     *
     * @param view 具体业务的接口对象
     */
    public GrowthActivityPresenter(IGrowthActivityView view) {
        super(view);
    }


    /**
     * 分页获取成长记录
     * @param pageindex
     * @param pagesize
     */
    public void getGrothList(int pageindex,int pagesize)
    {
         GetgrowRequestInfo info = new GetgrowRequestInfo();
        info.setDevice_imei(MyApplication.IMEI);
        info.setUser_phone(MyApplication.PHONE);
        info.setStart_time("2000-01-01 00:00:00");
        info.setEnd_time(DateUtils.getNowTime(DateUtils.dateFormat1) + " 23:59:59");
        info.setPage_index(pageindex);
        info.setPage_size(pagesize);

        try {
            netWorkManger.getGrowList(info).subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new BaseObserver<GetgrowResponseInfo>() {
                        @Override
                        public void onFail(String failMsg) {
                            iView.toast(failMsg);
                        }

                        @Override
                        public void onFail(int failId) {
                              iView.msgError("");
                        }

                        @Override
                        public void onSuccess(GetgrowResponseInfo bean) {
                            iView.GrowthListSuccess(bean.getLikeList(),bean.getTotalRecord());
                        }
                    });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
}
